home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Skunkware 5
/
Skunkware 5.iso
/
src
/
X11
/
tclMotif-1.4
/
tests
/
list.test.old
< prev
next >
Wrap
Text File
|
1995-06-29
|
8KB
|
399 lines
if {[string compare test [info procs test]] == 1} then \
{source defs}
# set VERBOSE 1
# set INTERACTIVE 1
############
# work procs
############
proc listItems {} {
.form.list getValues \
-items i -itemCount n
return "$n $i"
}
proc listSelectedItems {} {
.form.list getValues \
-selectedItems i -selectedItemCount n
return "$n $i"
}
proc indexToY {w n} {
# calculate the Y co-ord for an index in the list
$w getValues \
-height h -itemCount count \
-visibleItemCount vis
set y [expr {(2*$n - 1) * $h / (2*$count)}]
return $y
}
proc pause {} {
# pause, so that repeated button clicks are not
# mistaken for double clicks!
# this stuff doesn't work like it should.
# .form.list getValues -doubleClickInterval c
# set wait [expr {(2 * $c) / 1000}]
# if {$wait < 1} {
# set wait 1
# }
# exec sleep $wait
# so busy wait instead
set n 0
while {$n < 10000} {incr n}
}
proc getIO {} {
puts stdout "Press a key"
gets stdin s
}
proc buttonPress {w n} {
# simulate a button press
return [$w callActionProc ListBeginSelect() \
-type ButtonPress \
-x 0 -y [indexToY $w $n]]
}
proc buttonRelease {w n} {
# simulate a button release
return [$w callActionProc ListEndSelect() \
-type ButtonRelease \
-x 0 -y [indexToY $w $n]]
}
#############
# starts here
#############
xtAppInitialize -class List
. setValues -allowShellResize true
xmForm .form managed
xmList .form.list managed \
-visibleItemCount 4 \
-items "a, b, c, d" -itemCount 4
. realizeWidget
######################
# List element setting
######################
test list-1.1 {list items} {
listItems
} {4 a, b, c, d}
test list-1.2 {resetting list items} {
.form.list setValues \
-items "A, B, C, D, E" -itemCount 5
listItems
} {5 A, B, C, D, E}
test list-1.3 {clearing list items} {
.form.list setValues \
-items "" -itemCount 0
listItems
} {0 }
test list-1.4 {resetting list items} {
.form.list setValues \
-items "a, b, c, d" -itemCount 4
listItems
} {4 a, b, c, d}
################################
# Selecting list items by code #
################################
########
# select
########
test list-2.1 {selecting list item} {
.form.list setValues \
-selectedItems "b" -selectedItemCount 1
listSelectedItems
} {1 b}
##########
# reselect
##########
test list-2.2 {reselecting list items} {
.form.list setValues \
-selectedItems "a, c" -selectedItemCount 2
listSelectedItems
} {2 a, c}
#######
# clear
######
test list-2.3 {clearing list selection} {
.form.list setValues \
-selectedItems "" -selectedItemCount 0
listSelectedItems
} {0 }
##########
# reselect
##########
test list-2.4 {reselecting list items} {
.form.list setValues \
-selectedItems "a, b, c, d" -selectedItemCount 4
listSelectedItems
} {4 a, b, c, d}
###################################
# Modifying list items by methods #
###################################
########
# Adding
########
test list-3.1 {adding list item at front} {
.form.list addItem aa 1
listItems
} {5 aa, a, b, c, d}
test list-3.2 {adding list item at end} {
.form.list addItem e 0
listItems
} {6 aa, a, b, c, d, e}
test list-3.3 {adding list item in middle} {
.form.list addItem bb 4
listItems
} {7 aa, a, b, bb, c, d, e}
##########
# Deleting
##########
test list-3.4 {deleting list item at front} {
.form.list deleteItem aa
listItems
} {6 a, b, bb, c, d, e}
test list-3.5 {deleting list item at middle} {
.form.list deleteItem c
listItems
} {5 a, b, bb, d, e}
test list-3.6 {deleting all list items} {
.form.list deleteAllItems
listItems
} {0 }
test list-3.7 {adding item to empty list} {
.form.list addItem a 1
listItems
} {1 a}
test list-3.8 {deleting list item by position} {
.form.list deletePosition 1
listItems
} {0 }
####################
# callback testing #
####################
.form.list setValues \
-items "a, b, c, d" -itemCount 4
.form.list singleSelectionCallback listSelectedItems
test list-4.1 {single selection callback} {
.form.list setValues -selectionPolicy single_select \
-selectedItems "" -selectedItemCount 0
buttonPress .form.list 1
buttonRelease .form.list 1
} {1 a}
test list-4.2 {single selection callback} {
pause
.form.list setValues -selectionPolicy single_select \
-selectedItems "" -selectedItemCount 0
buttonPress .form.list 2
buttonRelease .form.list 2
listSelectedItems
} {1 b}
test list-4.3 {single selection callback} {
pause
.form.list setValues -selectionPolicy single_select \
-selectedItems "" -selectedItemCount 0
buttonPress .form.list 4
buttonRelease .form.list 4
} {1 d}
.form.list destroyWidget
############################
# % substitutions for list #
############################
proc singleCB {item item_position} {
return "$item $item_position"
}
proc multipleCB {selected_items} {
return $selected_items
}
xmList .form.list2 managed \
-items "a, b, c, d" -itemCount 4 \
-visibleItemCount 4
.form.list2 singleSelectionCallback {singleCB %item %item_position}
.form.list2 multipleSelectionCallback {multipleCB {%selected_items}}
###############
# Single select
###############
test list-5.1 {% substitutions for single select} {
.form.list2 setValues \
-selectionPolicy single_select \
-selectedItems "" \
-selectedItemCount 0
buttonPress .form.list2 2
buttonRelease .form.list2 2
} {b 2}
#################
# Multiple select
#################
test list-5.2 {% substitutions for multiple select} {
pause
.form.list2 setValues \
-selectionPolicy multiple_select \
-selectedItems "" \
-selectedItemCount 0
buttonPress .form.list2 2
buttonRelease .form.list2 2
pause
buttonPress .form.list2 3
buttonRelease .form.list2 3
} {b, c}
.form.list2 destroyWidget
###############################
# Selection of items by methods
###############################
xmList .form.list managed
.form.list setValues \
-items "a, b, c, d" \
-itemCount 4 \
-selectedItems "" \
-selectedItemCount 0 \
-selectionPolicy single_select
test list-6.1 {selectItem - single select} {
.form.list selectItem a false
.form.list selectItem c true
listSelectedItems
} {1 c}
test list-6.2 {selectItem - multiple select} {
.form.list setValues \
-items "a, b, c, d" \
-itemCount 4 \
-selectedItems "" \
-selectedItemCount 0 \
-selectionPolicy multiple_select
.form.list selectItem c false
.form.list selectItem a false
listSelectedItems
} {2 a, c}
#################################
# Deselection of items by methods
#################################
test list-7.1 {deselectItem - multiple select} {
.form.list setValues \
-items "a, b, c, d" \
-itemCount 4 \
-selectedItems "a, b, d" \
-selectedItemCount 3 \
-selectionPolicy multiple_select
.form.list deselectItem b
listSelectedItems
} {2 a, d}
test list-7.2 {deselectAllItems} {
.form.list deselectAllItems
listSelectedItems
} {0 }
################################
# Selection of items by position
################################
.form.list deselectAllItems
.form.list setValues \
-selectionPolicy multiple_select \
-items "a,b,c,d" \
-itemCount 4 \
-selectedItems "" \
-selectedItemCount 0
test list-8.1 {selectPosition} {
.form.list selectPosition 1 false
.form.list selectPosition 3 false
listSelectedItems
} {2 a, c}
test list-8.2 {deselectPosition} {
.form.list deselectPosition 1
listSelectedItems
} {1 c}
test list-8.3 {positionSelected - true} {
.form.list positionSelected 3
} {true}
test list-8.4 {positionSelected - false} {
.form.list positionSelected 2
} {false}
################
# Item existence
################
test list-9.1 {itemExists - true} {
.form.list itemExists c
} {true}
test list-9.2 {itemExists - false} {
.form.list itemExists ccccc
} {false}
#############
# Finish up #
#############
if { ! $INTERACTIVE} {
.form.list destroyWidget
.form destroyWidget
} else {
. mainLoop
}